﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;

public partial class Admin_Pages_FeedBackInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["login"] != null)
            {
                BindData();
            }
            else
            {
                Response.Redirect("../Login.aspx");
            }

            
        }
    }

    private void BindData()
    {
        try
        {
            int feedid = Convert.ToInt32(Request.Params["feedid"]);
            FeedBackUI feedUI = new FeedBackUI();
            DataSet ds = feedUI.Get(feedid);
            lblCustomer.Text = ds.Tables[0].Rows[0]["Username"].ToString();
            lblDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["Feed_Date"]).ToShortDateString();
            if (Convert.ToBoolean(ds.Tables[0].Rows[0]["Feed_Status"]) == true)
            {
                lblCheckStatus.Checked = true;
                lblCheckStatus.Enabled = false;
                btnSave.Enabled = false;
            }
            else
            {
                lblCheckStatus.Checked = false;
                lblCheckStatus.Enabled = true;
                btnSave.Enabled = true;
            }
            txtTitle.Text = ds.Tables[0].Rows[0]["Feed_Title"].ToString();
            txtContent.Text = ds.Tables[0].Rows[0]["Feed_Message"].ToString();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('This feedback is not exists'); window.location='../Pages/FeedBackList.aspx';</script>");
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (lblCheckStatus.Checked)
        {
            int feedid = Convert.ToInt32(Request.Params["feedid"]);
            FeedBackUI feedUI = new FeedBackUI();

            int result = feedUI.ChangeStatus(feedid,true);
            if (result > 0)
            {
                Response.Write("<script>alert('Change status successful'); window.location='../Pages/FeedBackList.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('Change status fail'); window.location='../Pages/FeedBackList.aspx';</script>");
            }
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Pages/FeedBackList.aspx");
    }
}
